home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / lib / init / mount-functions.sh next >
Encoding:
Text File  |  2007-04-10  |  3.0 KB  |  139 lines

  1. #
  2. # Functions used by several mount* scripts in initscripts package
  3. #
  4. # Sourcer must set PATH and include /lib/init in it because
  5. # domount() uses the custom readlink program
  6. #
  7. # Sourcer must also source /lib/lsb/init-functions.sh
  8.  
  9. # $1: directory
  10. is_empty_dir() {
  11.     for FILE in $1/* $1/.*
  12.     do
  13.         case "$FILE" in
  14.           "$1/.*") return 0 ;;
  15.           "$1/*"|"$1/."|"$1/..") continue ;;
  16.           *) return 1 ;;
  17.         esac
  18.     done
  19.     return 0
  20. }
  21.  
  22.  
  23. selinux_enabled () {
  24.     which selinuxenabled >/dev/null 2>&1 && selinuxenabled
  25. }
  26.  
  27.  
  28. # $1: file system type
  29. # $2: alternative file system type (or empty string if none)
  30. # $3: mount point
  31. # $4... : extra mount program options
  32. domount () {
  33.     MTPT="$3"
  34.     KERNEL="$(uname -s)"
  35.     # Figure out filesystem type
  36.     FSTYPE=
  37.     if [ "$1" = proc ]
  38.     then
  39.         case "$KERNEL" in
  40.             Linux|GNU) FSTYPE=proc ;;
  41.             *FreeBSD)  FSTYPE=linprocfs ;;
  42.             *)         FSTYPE=procfs ;;
  43.         esac
  44.     elif grep -E -qs "$1\$" /proc/filesystems
  45.     then
  46.         FSTYPE=$1
  47.     elif grep -E -qs "$2\$" /proc/filesystems
  48.     then
  49.         FSTYPE=$2
  50.     fi
  51.  
  52.     if [ ! "$FSTYPE" ]
  53.     then
  54.         if [ "$2" ]
  55.         then
  56.             log_warning_msg "Filesystem types '$1' and '$2' are not supported. Skipping mount."
  57.         else
  58.             log_warning_msg "Filesystem type '$1' is not supported. Skipping mount."
  59.         fi
  60.         return
  61.     fi
  62.  
  63.     # Get the options from /etc/fstab.
  64.     OPTS=
  65.     if [ -f /etc/fstab ]
  66.     then
  67.         exec 9<&0 </etc/fstab
  68.  
  69.         while read TAB_DEV TAB_MTPT TAB_FSTYPE TAB_OPTS TAB_REST
  70.         do
  71.             case "$TAB_DEV" in (""|\#*) continue ;; esac
  72.             [ "$MTPT" = "$TAB_MTPT" ] || continue
  73.             [ "$FSTYPE" = "$TAB_FSTYPE" ] || continue
  74.             case "$TAB_OPTS" in
  75.               noauto|*,noauto|noauto,*|*,noauto,*)
  76.                 exec 0<&9 9<&-
  77.                 return
  78.                 ;;
  79.               ?*)
  80.                 OPTS="-o$TAB_OPTS"
  81.                 ;;
  82.             esac
  83.             break
  84.         done
  85.  
  86.         exec 0<&9 9<&-
  87.     fi
  88.  
  89.     if [ ! -d "$MTPT" ]
  90.     then
  91.         log_warning_msg "Mount point '$MTPT' does not exist. Skipping mount."
  92.         return
  93.     fi
  94.  
  95.     if mountpoint -q "$MTPT"
  96.     then
  97.         return
  98.     fi
  99.  
  100.     # We give file system type as device name
  101.     if [ "$VERBOSE" != "no" ]; then
  102.         is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden."
  103.     fi
  104.     mount -n -t $FSTYPE $OPTS $4 $FSTYPE $MTPT
  105. }
  106.  
  107. #
  108. # Preserve /var/run and /var/lock mountpoints
  109. #
  110. pre_mountall ()
  111. {
  112.     # We may end up mounting something over top of /var, either directly
  113.     # or because /var is a symlink to something that's mounted.  So keep
  114.     # copies of the /var/run and /var/lock mounts elsewhere on the root
  115.     # filesystem so they can be moved back.
  116.     mkdir /dev/shm/var.run /dev/shm/var.lock
  117.     mount -n --bind /var/run /dev/shm/var.run
  118.     mount -n --bind /var/lock /dev/shm/var.lock
  119. }
  120.  
  121. #
  122. # Restore /var/run and /var/lock mountpoints
  123. #
  124. post_mountall ()
  125. {
  126.     # Make sure the new filesystem has a /var/run and /var/lock
  127.     [ -d /var/run ] || mkdir /var/run
  128.     [ -d /var/lock ] || mkdir /var/lock
  129.     
  130.     # Move the mountpoints back.  Fortunately mount seems to not care
  131.     # if these are the same thing (ie. /var didn't get changed) so we
  132.     # do this regardless
  133.     mount -n --move /dev/shm/var.run /var/run
  134.     mount -n --move /dev/shm/var.lock /var/lock
  135.     
  136.     # Clean up after ourselves
  137.     rmdir /dev/shm/var.run /dev/shm/var.lock
  138. }
  139.